# Based on the file vtkCompilerExtras.cmake
IF(CMAKE_COMPILER_IS_GNUCXX)
  INCLUDE(CheckCXXCompilerFlag)

  # Addtional warnings for GCC
  # -Wshadow has been removed due to eigen
  SET(CMAKE_CXX_FLAGS_WARN "-Wnon-virtual-dtor -Wno-long-long -ansi -Wcast-align -Wchar-subscripts -Wall -Wextra -Wpointer-arith -Wformat-security -Woverloaded-virtual -Wunused-parameter -fno-check-new -fno-common")

  # This flag is useful as not returning from a non-void function is an error
  # with MSVC, but it is not supported on all GCC compiler versions
  CHECK_CXX_COMPILER_FLAG(-Werror=return-type HAVE_GCC_ERROR_RETURN_TYPE)
  IF(HAVE_GCC_ERROR_RETURN_TYPE)
    SET(CMAKE_CXX_FLAGS_ERROR "-Werror=return-type")
  ENDIF(HAVE_GCC_ERROR_RETURN_TYPE)

  # Set up the debug CXX_FLAGS for extra warnings
  OPTION(BTK_EXTRA_COMPILER_WARNINGS "Add compiler flags to do stricter checking when building debug." OFF)
  IF(BTK_EXTRA_COMPILER_WARNINGS)
    SET(CMAKE_OLD_CXX_FLAGS_RELWITHDEBINFO 0 CACHE STRING "CMAKE_OLD_CXX_FLAGS_RELWITHDEBINFO old value")
    SET(CMAKE_OLD_CXX_FLAGS_DEBUG 0 CACHE STRING "CMAKE_OLD_CXX_FLAGS_DEBUG old value")
    MARK_AS_ADVANCED(CMAKE_OLD_CXX_FLAGS_RELWITHDEBINFO CMAKE_OLD_CXX_FLAGS_DEBUG)
    IF(NOT CMAKE_OLD_CXX_FLAGS_RELWITHDEBINFO)
      SET(CMAKE_OLD_CXX_FLAGS_RELWITHDEBINFO ${CMAKE_CXX_FLAGS_RELWITHDEBINFO} CACHE STRING "CMAKE_OLD_CXX_FLAGS_RELWITHDEBINFO old value" FORCE)
    ENDIF(NOT CMAKE_OLD_CXX_FLAGS_RELWITHDEBINFO)
    IF(NOT CMAKE_OLD_CXX_FLAGS_DEBUG)
      SET(CMAKE_OLD_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG} CACHE STRING "CMAKE_OLD_CXX_FLAGS_DEBUG old value" FORCE)
    ENDIF(NOT CMAKE_OLD_CXX_FLAGS_DEBUG)
    SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_OLD_CXX_FLAGS_RELWITHDEBINFO} ${CMAKE_CXX_FLAGS_WARN}" CACHE STRING "Flags used by the compiler during Release with Debug builds." FORCE)
    SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_OLD_CXX_FLAGS_DEBUG} ${CMAKE_CXX_FLAGS_WARN} ${CMAKE_CXX_FLAGS_ERROR}" CACHE STRING "Flags used by the compiler during debug builds." FORCE)
  ELSE(BTK_EXTRA_COMPILER_WARNINGS)
    IF(CMAKE_OLD_CXX_FLAGS_RELWITHDEBINFO)
      SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO ${CMAKE_OLD_CXX_FLAGS_RELWITHDEBINFO} CACHE STRING "Flags used by the compiler during Release with Debug builds." FORCE)
      SET(CMAKE_OLD_CXX_FLAGS_RELWITHDEBINFO 0 CACHE STRING "" FORCE)
    ENDIF(CMAKE_OLD_CXX_FLAGS_RELWITHDEBINFO)
    IF(CMAKE_OLD_CXX_FLAGS_DEBUG)
      SET(CMAKE_CXX_FLAGS_DEBUG ${CMAKE_OLD_CXX_FLAGS_DEBUG} CACHE STRING "Flags used by the compiler during debug builds." FORCE)
      SET(CMAKE_OLD_CXX_FLAGS_DEBUG 0 CACHE STRING "" FORCE)
    ENDIF(CMAKE_OLD_CXX_FLAGS_DEBUG)
  ENDIF(BTK_EXTRA_COMPILER_WARNINGS)
ENDIF(CMAKE_COMPILER_IS_GNUCXX)